package com.bite.system.Test;

import com.bite.common.core.domain.R;
import com.bite.common.core.enums.ResultCode;
import com.bite.system.Test.domain.ValidationDTO;
import com.bite.system.Test.service.ITestService;
import com.bite.system.domain.sysuser.SysUser;
import com.bite.common.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private ITestService testService;

    @Autowired
    private RedisService redisService;

    @GetMapping("/list")
    public List<?> list(){
        return testService.list();
    }

    @RequestMapping("apifoxTest")
    public R<String> apifoxTest(String id){
        R<String> result = new R<>();
        result.setMsg(ResultCode.SUCCESS.getMsg());
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setData("Apifox测试");
        return result;
    }

    @RequestMapping("/log")
    public String log(){
        log.info("我是info");
        log.error("我是error");
        return "日志测试";
    }

    @GetMapping("/redisAddAndGet")
    public String redisAddAndGet(){
        SysUser sysUser = new SysUser();
        sysUser.setUserAccount("redisTest");
        redisService.setCacheObject("u",sysUser);
        SysUser u = redisService.getCacheObject("u", SysUser.class);
        return u.toString();
    }

    @GetMapping("/validation")
    public String validation(@Validated ValidationDTO validationDTO) {
        return "参数测试";
    }
}
